library(fs)
library(parallel)
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(patchwork)
library(here)
## here() starts at /Users/AlessandraPescina/OneDrive - Politecnico di Milano/ANNO 5/secondo semestre/TESI/Tesi/Tesi-KI
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
setwd(here())

path <- "./wrapper_MM/plots_500/"
files <- list.files(path, pattern = "\\.RData$", full.names = TRUE)
lapply(files, load, .GlobalEnv)
## [[1]]
## [1] "plots_bias"
## 
## [[2]]
## [1] "plots_cov"
## 
## [[3]]
## [1] "plots_distr"
## 
## [[4]]
## [1] "plots_power"
## 
## [[5]]
## [1] "plots_errorI"
plots_bias500 <- plots_bias
remove(plots_bias)

plots_cov500 <- plots_cov
remove(plots_cov)

plots_errorI500 <- plots_errorI
remove(plots_errorI)

plots_power500 <- plots_power
remove(plots_power)

plots_distr500 <- plots_distr
remove(plots_distr)
path <- "./wrapper_MM/plots_2K/"
files <- list.files(path, pattern = "\\.RData$", full.names = TRUE)
lapply(files, load, .GlobalEnv)
## [[1]]
## [1] "plots_bias"
## 
## [[2]]
## [1] "plots_cov"
## 
## [[3]]
## [1] "plots_distr"
## 
## [[4]]
## [1] "plots_power"
## 
## [[5]]
## [1] "plots_errorI"
plots_bias2K <- plots_bias
remove(plots_bias)

plots_cov2K <- plots_cov
remove(plots_cov)

plots_errorI2K <- plots_errorI
remove(plots_errorI)

plots_power2K <- plots_power
remove(plots_power)

plots_distr2K <- plots_distr
remove(plots_distr)
path <- "./wrapper_MM/plots_5K/"
files <- list.files(path, pattern = "\\.RData$", full.names = TRUE)
lapply(files, load, .GlobalEnv)
## [[1]]
## [1] "plots_bias"
## 
## [[2]]
## [1] "plots_cov"
## 
## [[3]]
## [1] "plots_distr"
## 
## [[4]]
## [1] "plots_power"
## 
## [[5]]
## [1] "plots_errorI"
plots_bias5K<- plots_bias
remove(plots_bias)

plots_cov5K <- plots_cov
remove(plots_cov)

plots_errorI5K <- plots_errorI
remove(plots_errorI)

plots_power5K <- plots_power
remove(plots_power)

plots_distr5K <- plots_distr
remove(plots_distr)
path <- "./wrapper_MM/plots_10K/"
files <- list.files(path, pattern = "\\.RData$", full.names = TRUE)
lapply(files, load, .GlobalEnv)
## [[1]]
## [1] "plots_bias"
## 
## [[2]]
## [1] "plots_cov"
## 
## [[3]]
## [1] "plots_distr"
## 
## [[4]]
## [1] "plots_power"
## 
## [[5]]
## [1] "plots_se"
## 
## [[6]]
## [1] "plots_errorI"
plots_bias10K<- plots_bias
remove(plots_bias)

plots_cov10K <- plots_cov
remove(plots_cov)

plots_errorI10K <- plots_errorI
remove(plots_errorI)

plots_power10K <- plots_power
remove(plots_power)

plots_distr10K <- plots_distr
remove(plots_distr)

BIAS 500

bias_500 <- (plots_bias500[[1]] + plots_bias500[[3]]) / 
                 (plots_bias500[[5]] + plots_bias500[[7]]) +
                 plot_layout(guides = "collect")
bias_500 & 
  ylim(0, 3)

COVERAGE 500

cov_500 <- (plots_cov500[[1]] + plots_cov500[[2]]) / 
                 (plots_cov500[[3]] + plots_cov500[[4]]) +
                 plot_layout(guides = "collect")
cov_500

ERROR TYPE I 500

p1 <- plots_errorI500[[1]][[1]] + labs(title = NULL,  x = "1 year observation scheme")+ theme(legend.position = "none")
p2 <- plots_errorI500[[2]][[1]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI500[[3]][[1]] + labs(title = NULL, x = "3-6 years observation scheme")
p4 <- plots_errorI500[[4]][[1]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_500_trans1 <- (p1 + p2) / (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia-free -> Dementia", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 
p1 <- plots_errorI500[[1]][[2]] + labs(title = NULL,  x = "1 year observation scheme") + theme(legend.position = "none")
p2 <- plots_errorI500[[2]][[2]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI500[[3]][[2]] + labs(title = NULL, x = "3-6 years observation scheme") 
p4 <- plots_errorI500[[4]][[2]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_500_trans3 <- (p1 + p2 )/ (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia -> Death", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 


typeIerror_500_trans1

typeIerror_500_trans3

POWER 500

p1 <- plots_power500[[1]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power500[[4]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power500[[7]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power500[[10]] +labs(title =NULL, x = "irregular observation scheme")

power_500_trans1 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Dementia",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power500[[2]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power500[[5]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power500[[8]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power500[[11]] +labs(title =NULL, x = "irregular observation scheme")

power_500_trans2 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power500[[3]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power500[[6]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power500[[9]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power500[[12]] +labs(title =NULL, x = "irregular observation scheme")

power_500_trans3 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")
  
power_500_trans1

power_500_trans2

power_500_trans3

COEFFICIENTS DISTRIBUTION

p1 <- plots_distr500[[1]][[1]] + 
  labs(title = NULL, x = "1 year observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p2 <- plots_distr500[[2]][[1]] + 
  labs(title = NULL, x = "3 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p3 <- plots_distr500[[3]][[1]] + 
  labs(title = NULL, x = "3-6 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p4 <- plots_distr500[[4]][[1]] + 
  labs(title = NULL, x = "irregular observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

distr_500_trans1 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Coefficients density distribution for transition Dementia-free -> Dementia",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_distr500[[1]][[2]] + 
  labs(title = NULL, x = "1 year observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p2 <- plots_distr500[[2]][[2]] + 
  labs(title = NULL, x = "3 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p3 <- plots_distr500[[3]][[2]] + 
  labs(title = NULL, x = "3-6 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p4 <- plots_distr500[[4]][[2]] + 
  labs(title = NULL, x = "irregular observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

distr_500_trans2 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Coefficients density distribution for transition Dementia-free -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_distr500[[1]][[3]] + 
  labs(title = NULL, x = "1 year observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p2 <- plots_distr500[[2]][[3]] + 
  labs(title = NULL, x = "3 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p3 <- plots_distr500[[3]][[3]] + 
  labs(title = NULL, x = "3-6 years observation scheme") + 
  theme(axis.title.x = element_text(size = 8))

p4 <- plots_distr500[[4]][[3]] + 
  labs(title = NULL, x = "irregular observation scheme") + 
  theme(axis.title.x = element_text(size = 8))
distr_500_trans3 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Coefficients density distribution for transition Dementia -> Death",  
  theme = theme(plot.title = element_text(size = 14, hjust = 0.5)))+  
  plot_layout(guides = "collect")
  
distr_500_trans1

distr_500_trans2

distr_500_trans3

BIAS_2K

plots_bias_2K <- (plots_bias2K[[1]] + plots_bias2K[[3]]) / 
                 (plots_bias2K[[5]] + plots_bias2K[[7]]) +
                 plot_layout(guides = "collect")
plots_bias_2K & 
  ylim(0, 2)

COVERAGE 2K

cov_2K <- (plots_cov2K[[1]] + plots_cov2K[[2]]) / 
                 (plots_cov2K[[3]] + plots_cov2K[[4]]) +
                 plot_layout(guides = "collect")
cov_2K

ERROR TYPE I 2K

p1 <- plots_errorI2K[[1]][[1]] + labs(title = NULL,  x = "1 year observation scheme")+ theme(legend.position = "none")
p2 <- plots_errorI2K[[2]][[1]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI2K[[3]][[1]] + labs(title = NULL, x = "3-6 years observation scheme")
p4 <- plots_errorI2K[[4]][[1]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_2K_trans1 <- (p1 + p2) / (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia-free -> Dementia", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 
p1 <- plots_errorI2K[[1]][[2]] + labs(title = NULL,  x = "1 year observation scheme") + theme(legend.position = "none")
p2 <- plots_errorI2K[[2]][[2]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI2K[[3]][[2]] + labs(title = NULL, x = "3-6 years observation scheme") 
p4 <- plots_errorI2K[[4]][[2]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_2K_trans3 <- (p1 + p2 )/ (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia -> Death", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 


typeIerror_2K_trans1

typeIerror_2K_trans3

POWER 2K

p1 <- plots_power2K[[1]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power2K[[4]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power2K[[7]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power2K[[10]] +labs(title =NULL, x = "irregular observation scheme")

power_2K_trans1 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Dementia",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power2K[[2]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power2K[[5]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power2K[[8]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power2K[[11]] +labs(title =NULL, x = "irregular observation scheme")

power_2K_trans2 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power2K[[3]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power2K[[6]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power2K[[9]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power2K[[12]] +labs(title =NULL, x = "irregular observation scheme")

power_2K_trans3 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")
  
power_2K_trans1

power_2K_trans2

power_2K_trans3

BIAS_5K

plots_bias_5K <- (plots_bias5K[[1]] + plots_bias5K[[3]]) / 
                 (plots_bias5K[[5]] + plots_bias5K[[7]]) +
                 plot_layout(guides = "collect")
plots_bias_5K & 
  ylim(0, 1)

COVERAGE 5K

cov_5K <- (plots_cov5K[[1]] + plots_cov5K[[2]]) / 
                 (plots_cov5K[[3]] + plots_cov5K[[4]]) +
                 plot_layout(guides = "collect")
cov_5K

ERROR TYPE I 5K

p1 <- plots_errorI5K[[1]][[1]] + labs(title = NULL,  x = "1 year observation scheme")+ theme(legend.position = "none")
p2 <- plots_errorI5K[[2]][[1]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI5K[[3]][[1]] + labs(title = NULL, x = "3-6 years observation scheme")
p4 <- plots_errorI5K[[4]][[1]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_5K_trans1 <- (p1 + p2) / (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia-free -> Dementia", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 
p1 <- plots_errorI5K[[1]][[2]] + labs(title = NULL,  x = "1 year observation scheme") + theme(legend.position = "none")
p2 <- plots_errorI5K[[2]][[2]] + labs(title = NULL,  x = "3 years observation scheme") 
p3 <- plots_errorI5K[[3]][[2]] + labs(title = NULL, x = "3-6 years observation scheme") 
p4 <- plots_errorI5K[[4]][[2]] + labs(title = NULL,  x = "irregular observation scheme") 

typeIerror_5K_trans3 <- (p1 + p2 )/ (p3 + p4) +
                  plot_layout(guides = "collect", widths = unit(rep(1, 4), "null")) +
                  plot_annotation(
                    title ="Heatmap of Type I Error by Method and Covariate for transition Dementia -> Death", 
                    theme = theme(plot.title = element_text(size = 15, hjust = 0.5)),
                  ) 


typeIerror_5K_trans1

typeIerror_5K_trans3

POWER 5K

p1 <- plots_power5K[[1]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power5K[[4]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power5K[[7]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power5K[[10]] +labs(title =NULL, x = "irregular observation scheme")

power_5K_trans1 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Dementia",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power5K[[2]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power5K[[5]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power5K[[8]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power5K[[11]] +labs(title =NULL, x = "irregular observation scheme")

power_5K_trans2 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia-free -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")

p1 <- plots_power5K[[3]] + labs(title =NULL, x = "1 year observation scheme")
p2 <- plots_power5K[[6]] + labs(title =NULL, x = "3 years observation scheme")
p3 <- plots_power5K[[9]] + labs(title =NULL, x = "3-6 years observation scheme")
p4 <- plots_power5K[[12]] +labs(title =NULL, x = "irregular observation scheme")

power_5K_trans3 <- (p1 + p2) / (p3 + p4) + 
  plot_layout(guides = "collect") + plot_annotation(
  title ="Heatmap of Power by Method and Covariate for transition Dementia -> Death",  
  theme = theme(plot.title = element_text(size = 15, hjust = 0.5)))+  
  plot_layout(guides = "collect")
  
power_5K_trans1

power_5K_trans2

power_5K_trans3

BIAS COMPARISON (3-6)

p1 <- plots_bias500[[5]] + 
  labs(title =NULL, caption = "500 observations") +
  geom_point(size=0.5)
p2 <- plots_bias2K[[5]] + 
  labs(title= NULL, caption = "2K observations") +
  geom_point(size=0.5)
p3 <- plots_bias5K[[5]] + 
  labs(title= NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_bias10K[[5]] + 
  labs(title= NULL, caption = "10K observations") +
  geom_point(size=0.5)


plots_bias_all <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Bias comparison (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

plots_bias_all & 
  ylim(0, 3)

COVERAGE COMPARISON (3-6)

p1 <- plots_cov500[[3]] + 
  labs(title =NULL, caption = "500 observations") +
  geom_point(size=0.5)
p2 <- plots_cov2K[[3]] + 
  labs(title= NULL, caption = "2K observations") +
  geom_point(size=0.5)
p3 <- plots_cov5K[[3]] + 
  labs(title= NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_cov10K[[3]] + 
  labs(title= NULL, caption = "10K observations") +
  geom_point(size=0.5)

plots_cov_all <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Coverage comparison (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

plots_cov_all & 
  ylim(0, 1)

ERROR TYPE I COMPARISON (3-6)

p1 <- plots_errorI500[[3]][[1]] + 
  labs(title =NULL, x=NULL, caption = "500 observations") +
  geom_point(size=0.5) 
p2 <- plots_errorI2K[[3]][[1]] + 
  labs(title= NULL, x=NULL, caption = "2K observations") +
  geom_point(size=0.5)
p3 <- plots_errorI5K[[3]][[1]] + 
  labs(title= NULL, x=NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_errorI5K[[3]][[1]] + 
  labs(title= NULL, x=NULL, caption = "10K observations") +
  geom_point(size=0.5)

plots_errorI_all_trans1 <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Type I error comparison on transition Dementia-free -> Dementia (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

p1 <- plots_errorI500[[3]][[2]] + 
  labs(title =NULL, x=NULL, caption = "500 observations") +
  geom_point(size=0.5) 
p2 <- plots_errorI2K[[3]][[2]] + 
  labs(title= NULL, x=NULL, caption = "2K observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")
p3 <- plots_errorI5K[[3]][[2]] + 
  labs(title= NULL, x=NULL, caption = "5K observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")
p4 <- plots_errorI5K[[3]][[2]] + 
  labs(title= NULL, x=NULL, caption = "10K observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")

plots_errorI_all_trans3 <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Type I error comparison on transition Dementia-> Death (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

plots_errorI_all_trans1

plots_errorI_all_trans3

POWER COMPARISON (3-6)

p1 <- plots_power500[[7]] + 
  labs(title =NULL, x=NULL, caption = "500 observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")
p2 <- plots_power2K[[7]] + 
  labs(title= NULL, x=NULL, caption = "2K observations") +
  geom_point(size=0.5)
p3 <- plots_power5K[[7]] + 
  labs(title= NULL, x=NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_power5K[[7]] + 
  labs(title= NULL, x=NULL, caption = "10K observations") +
  geom_point(size=0.5)

plots_power_all_trans1 <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Power comparison on transition Dementia-free -> Dementia (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

p1 <- plots_power500[[8]] + 
  labs(title =NULL, x=NULL, caption = "500 observations") +
  geom_point(size=0.5)
p2 <- plots_power2K[[8]] + 
  labs(title= NULL, x=NULL, caption = "2K observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")
p3 <- plots_power5K[[8]] + 
  labs(title= NULL, x=NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_power5K[[8]] + 
  labs(title= NULL, x=NULL, caption = "10K observations") +
  geom_point(size=0.5)

plots_power_all_trans2 <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Power comparison on transition Dementia-free-> Death (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

p1 <- plots_power500[[9]] + 
  labs(title =NULL, x=NULL, caption = "500 observations") +
  geom_point(size=0.5)+ theme(legend.position = "none")
p2 <- plots_power2K[[9]] + 
  labs(title= NULL, x=NULL, caption = "2K observations") + theme(legend.position = "none")
  geom_point(size=0.5)
## geom_point: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity
p3 <- plots_power5K[[9]] + 
  labs(title= NULL, x=NULL, caption = "5K observations") +
  geom_point(size=0.5)
p4 <- plots_power5K[[9]] + 
  labs(title= NULL, x=NULL, caption = "10K observations") +
  geom_point(size=0.5)

plots_power_all_trans3 <- ( p1+p2) / (p3+p4) +
                 plot_layout(guides = "collect") + 
  plot_annotation(title = "Power comparison on transition Dementia-> Death (3-6 years)",
    theme = theme(plot.title = element_text(size = 16, face = "bold", hjust = 0.5)))

plots_power_all_trans1

plots_power_all_trans2

plots_power_all_trans3